#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    setFixedSize(8*64,8*64);//固定窗口大小
    pbox=new boxgame;
    pmap=new QPainter(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::keyPressEvent(QKeyEvent *event)
{
pbox->keydown(event);//pbox指针完成对按键处理的指令
if(pbox->gameover()){
    this->close();
}
}

void Widget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
    pmap->begin(this);
    pbox->drawmap(pmap);
    pmap->end();
    update();
}
